package com.tao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tao.dao.ListMapper;
import com.tao.entity.Help;
import com.tao.service.ListService;
import com.tao.vo.HelpInfoVo;
import com.tao.vo.ListDetailVo;
import com.tao.vo.ListVo;
import io.netty.util.internal.ObjectUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 张祎洋
 * @date 2023/5/27
 * @content :ListService实现类，ListService的具体实现
 */
@Service
public class ListServiceImpl extends ServiceImpl<ListMapper, Help> implements ListService {
    @Resource
    private ListMapper listMapper;

    public void getPageInfo(List<ListVo> helps, Map<String,Object> data){
        PageInfo<ListVo> pageInfo = new PageInfo<>(helps);
        data.put("total",pageInfo.getTotal());
        data.put("totalPage",pageInfo.getPages());
        data.put("rows",pageInfo.getList());
    }


    @Override
    public Map<String, Object> getHelpByHelpStatus(Integer pageNum, Integer pageSize, Long categoryId, String sort) {
        Map<String,Object> data= new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        List<ListVo> helps = listMapper.getHelpByHelpStatus(sort);
        getPageInfo(helps,data);
        return data;
    }

    @Override
    public Map<String,Object> getHelpByHelpStatusAll(Integer pageNum, Integer pageSize, Long categoryId, String sort){
        Map<String,Object> data= new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        List<ListVo> helps = listMapper.getHelpByHelpStatusAll(categoryId,sort);
        getPageInfo(helps,data);
        return data;
    }

    @Override
    public List<ListVo> getHelpByReward(Long hasReward){
        return listMapper.getHelpByReward(hasReward);
    }

    @Override
    public Map<String,Object> getHelpBySearch(Integer pageNum, Integer pageSize, Long categoryId, String sort,String filter) {
        Map<String, Object> data = new HashMap<>();
        PageHelper.startPage(pageNum, pageSize);
        List<ListVo> helps = listMapper.getHelpBySearch(categoryId, sort, filter);
        getPageInfo(helps, data);
        return data;
    }

    @Override
    public ListDetailVo getHelpByDetail(Long id){
        return listMapper.getHelpByDetail(id);
    }



}
